﻿namespace DbUp.Engine.Preprocessors
{
    internal class SchemaVariableSubstitutionPreprocessor : IScriptPreprocessor
    {
        private readonly string schema;

        /// <summary>
        /// Initializes a new instance of the <see cref="VariableSubstitutionPreprocessor"/> class.
        /// </summary>
        /// <param name="schema">The value to substitute for the $schema$ variable in scripts</param>
        public SchemaVariableSubstitutionPreprocessor(string schema)
        {
            this.schema = schema;
        }

        /// <summary>
        /// Substitutes variables 
        /// </summary>
        /// <param name="contents"></param>
        public string Process(string contents)
        {
            return contents.Replace("$schema$", schema);
        }
    }
}